package com.zzyl.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.DeviceDataPageReqDto;
import com.zzyl.mapper.DeviceDataMapper;
import com.zzyl.service.DeviceDataService;
import com.zzyl.vo.DeviceDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @version 1.0
 * @Author 小王要变胖
 * @Date 2025/2/13 10:20
 * @注释
 */
@Service
public class DeviceDataServiceImpl implements DeviceDataService {
    @Autowired
    private DeviceDataMapper deviceDataMapper;

    @Override
    public PageResponse<DeviceDataVo> getPage(DeviceDataPageReqDto deviceDataPageReqDto) {
        LocalDateTime startTime = LocalDateTimeUtil.of(deviceDataPageReqDto.getStartTime());
        LocalDateTime endTime = LocalDateTimeUtil.of(deviceDataPageReqDto.getEndTime());
        deviceDataPageReqDto.setStartDate(startTime);
        deviceDataPageReqDto.setEndDate(endTime);

        PageHelper.startPage(deviceDataPageReqDto.getPageNum(),deviceDataPageReqDto.getPageSize());


        Page<DeviceDataVo> page = deviceDataMapper.getPage(deviceDataPageReqDto);
        return PageResponse.of(page,DeviceDataVo.class);
    }
}
